package com.mega.ycy.mixin;

import com.mega.ycy.Yiciyuan_EVENT;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(EntityPlayerSP.class)
public abstract class SPMixin extends EntityPlayer {
    public SPMixin(World worldIn, GameProfile gameProfileIn) {
        super(worldIn, gameProfileIn);
    }

    private boolean is() {
        return Yiciyuan_EVENT.isSafe(this);
    }

    @Override
    public float getHealth() {
        if (is())
            return 20F;
        if (Yiciyuan_EVENT.isDeath(this))
            return 0F;
        return super.getHealth();
    }

    @Override
    public float getMaxHealth() {
        if (is())
            return 20F;
        return super.getMaxHealth();
    }

    @Override
    public boolean isEntityAlive() {
        if (is())
            return true;
        if (Yiciyuan_EVENT.isDeath(this))
            return false;
        return super.isEntityAlive();
    }

    @Override
    public void onRemovedFromWorld() {
        if (!is())
            super.onRemovedFromWorld();
    }

    @Override
    public void onKillCommand() {
        if (!is())
            super.onKillCommand();
    }

    @Override
    public boolean attackEntityFrom(DamageSource source, float amount) {
        if (is())
            return false;
        return super.attackEntityFrom(source, amount);
    }
}
